/*
* 作者:蘇文宏.
* 學號:8324057
* 建議使用有 jit 的 jvm 執行,否則速度會很慢.
*/
import java.awt.*;
public final class MyPanel extends Panel{
Button newWindow,redraw;
Checkbox lineCheck,ballCheck;
DrawPanel drawer;
boolean isDrawLine = false,isDrawBall = true;
MyPanel(){
setLayout(new BorderLayout());
setBackground(Color.white);//背景使用白色.
Panel panel = new Panel();
panel.setLayout(new GridLayout(0,1));
Label lb;
panel.add(lb = new Label("Author : 蘇文宏 Wen-Hung Su",Label.CENTER));
lb.setForeground(Color.blue);
panel.add(lb = new Label("E-mail : b8324057@student.nsysu.edu.tw",lb.CENTER));
lb.setForeground(Color.blue);
add("North",panel);
add("Center",drawer = new DrawPanel(this));
panel = new Panel();
panel.setLayout(new GridLayout(1,0));//row = 1,column = 不限.
panel.add(redraw = new Button("Repaint"));
panel.add(newWindow = new Button("New Window"));
panel.add(lineCheck = new Checkbox("Line",null,isDrawLine));//false
panel.add(ballCheck = new Checkbox("Ball",null,isDrawBall));//true
add("South",panel);
}
public boolean action(Event evt,Object obj){
if (evt.target instanceof Button){
if (evt.target == redraw){//按下『重繪』鍵.
drawer.repaint();
return true;
}
else if (evt.target == newWindow){//按下『新視窗』鍵.
MyFrame frame = new MyFrame("[ WinHw4 ]");
frame.setLayout(new BorderLayout());
frame.add("Center", new MyPanel());
frame.pack();
frame.show();
return true;
}
}//end of 如果是按鍵.
else if(evt.target instanceof Checkbox){
if(evt.target == lineCheck){
isDrawLine = lineCheck.getState();
return true;
}
else if(evt.target == ballCheck){
isDrawBall = ballCheck.getState();
return true;
}
}//end of 如果是檢查盒.
return false;
}
}//end of class MyPanel